package StudyCode.summary.mycollection;

import java.util.Iterator;
import java.util.NoSuchElementException;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class OneElementUnmodifiableIterator {
	public static Iterator oneElementUnmodifiableIterator(final Object elem) {
		return new Iterator() {
			boolean shot = false;

			public boolean hasNext() {
				return (!shot);
			}

			public Object next() {
				if (shot)
					throw new NoSuchElementException();
				else {
					shot = true;
					return elem;
				}
			}

			public void remove() {
				throw new UnsupportedOperationException(
						"remove()不支持.");
			}
		};
	}
}
